unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Spin, StdCtrls, Registry, Globals;

type
  TSettingsForm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    CheckBox5: TCheckBox;
    Edit1: TEdit;
    SpinEdit1: TSpinEdit;
    SpinEdit2: TSpinEdit;
    Button4: TButton;
    Button5: TButton;
    CheckBox2: TCheckBox;
    GroupBox3: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Edit2: TEdit;
    GroupBox2: TGroupBox;
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  SettingsForm: TSettingsForm;

implementation

{$R *.DFM}

procedure TSettingsForm.Button5Click(Sender: TObject);
begin
     Self.ModalResult:=mrCancel;
     Release;
end;

procedure TSettingsForm.Button4Click(Sender: TObject);
begin
     If RadioButton2.Checked=True Then
     Begin
          If Edit2.Text='' Then
          Begin
               MessageBeep(mb_ICONEXCLAMATION);
               Application.MessageBox('Please Select A Directory Using The Browse Button...','Assign Home Directory',mb_OK + mb_ICONEXCLAMATION);
               Exit;
          End;
     End;
     With TRegistry.Create Do
     Begin
          Try
             RootKey:=HKEY_LOCAL_MACHINE;
             If OpenKey('Software\Gideon Vos\FTPS\1.0\Settings',True) Then
             Begin
                  AutoStart:=CheckBox2.Checked;
                  ReadOnly:=CheckBox5.Checked;
                  LogonHome:=RadioButton1.Checked;
                  HomeDir:=Edit2.Text;
                  MaxConnections:=SpinEdit1.Value;
                  FTPPort:=SpinEdit2.Value;
                  FTPBanner:=Edit1.Text;
                  If CheckBox2.Checked Then WriteString('AutoStart','Y') Else WriteString('AutoStart','N');
                  If CheckBox5.Checked Then WriteString('ReadOnly','Y') Else WriteString('ReadOnly','N');
                  If RadioButton1.Checked Then WriteString('LogonDir','Home') Else WriteString('LogonDir','');
                  WriteInteger('MaxConnections',SpinEdit1.Value);
                  WriteInteger('FTPPort',SpinEdit2.Value);
                  WriteString('FTPBanner',Edit1.Text);
                  WriteString('HomeDir',Edit2.Text);
             End;
          Finally
             Free;
          End;
     End;
     Self.ModalResult:=mrOK;
     Release;
end;

procedure TSettingsForm.FormCreate(Sender: TObject);
var Tmp:String;
begin
     With TRegistry.Create Do
     Begin
          Try
             RootKey:=HKEY_LOCAL_MACHINE;
             If OpenKey('Software\Gideon Vos\FTPS\1.0\Settings',True) Then
             Begin
                  If ValueExists('AutoStart') Then Tmp:=ReadString('AutoStart');
                  If Tmp='Y' Then AutoStart:=True Else AutoStart:=False;
                  If ValueExists('ReadOnly') Then Tmp:=ReadString('ReadOnly');
                  If Tmp='Y' Then ReadOnly:=True Else ReadOnly:=False;
                  If ValueExists('MaxConnections') Then MaxConnections:=ReadInteger('MaxConnections');
                  If ValueExists('FTPPort') Then FTPPort:=ReadInteger('FTPPort');
                  If ValueExists('FTPBanner') Then FTPBanner:=ReadString('FTPBanner');
                  If ValueExists('LogonDir') Then Tmp:=ReadString('LogonDir') Else Tmp:='Home';
                  If Tmp='Home' Then LogonHome:=True Else LogonHome:=False;
                  If ValueExists('HomeDir') Then HomeDir:=ReadString('HomeDir');
             End;
          Finally
             Free;
          End;
     End;
     CheckBox2.Checked:=AutoStart;
     CheckBox5.Checked:=ReadOnly;
     SpinEdit1.Value:=MaxConnections;
     SpinEdit2.Value:=FTPPort;
     Edit1.Text:=FTPBanner;
     Edit2.Text:=HomeDir;
     If LogonHome Then RadioButton1.Checked:=True Else RadioButton2.Checked:=True;
end;

end.
